package com.ruoyi.web.controller.scheduled;

import com.ruoyi.framework.web.service.SigninService;
import com.ruoyi.system.mapper.PurchaseRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ScheduledController {
    @Autowired
    private SigninService signinService;
    @Autowired
    private PurchaseRecordMapper purchaseRecordMapper;
    /**
     * 每周一00点执行，重置一级抽奖次数
     */
    @Scheduled(cron = "0 0 0 * * 1")
    public void resetCount() {
        //每周一00点执行
        signinService.updateWeeksCount();
        log.info("重置本周签到数据");
    }

    /**
     * 每天00点执行，更新二级抽奖次数
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void updateLevelTwoCount() {
        //每周一00点执行
        signinService.updateLevelTwoCount();
        log.info("更新二级奖池抽奖次数");
    }

    /**
     * 每周一00点执行，更新三级抽奖次数
     */
    @Scheduled(cron = "0 0 0 * * 1")
    public void updateLevelThreeCount() {
        //每周一00点执行
        signinService.updateLevelThreeCount();
        log.info("更新三级奖池抽奖次数");
    }

    /**
     * 每分钟执行一次，更新超时未支付的订单
     */
    @Scheduled(cron = "0 * * * * ?")
    public void updatePaymentStatus() {
        //每分钟执行一次
        purchaseRecordMapper.updatePaymentStatus();
        log.info("更新超时未支付订单的订单状态");
    }
}
